﻿using Edu.Abstracts;
using Edu.Contracts;
using Edu.Pages;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;

namespace Edu.Web.Pages.UserAchievement
{
    public class CreateModalModel : EduPageModelBase
    {
        private IUserAchievementAppService _appService;
        private IAchievementAppService _achievementAppService;

        [BindProperty]
        public UserAchievementCreateDto CreateDto { get; set; }

        public List<SelectListItem> Achievements { get; set; } = new List<SelectListItem>();

        public CreateModalModel(IUserAchievementAppService userAchievementAppService, IAchievementAppService achievementAppService)
        {
            _appService = userAchievementAppService;
            _achievementAppService = achievementAppService;
        }

        public async Task OnGet()
        {
            var achievements = await _achievementAppService.GetListAsync(new PagedAndSortedResultRequestDto()
            {
                SkipCount = 0,
                MaxResultCount = 99999
            });

            foreach (var item in achievements.Items)
            {
                var belong = item.Belong == Entitys.AchievementBelong.Student ? "学生" : "教师";

                Achievements.Add(new SelectListItem
                {
                    Value = item.Id.ToString(),
                    Text = $"{item.Name}({belong})"
                });
            }
        }


        public async Task<IActionResult> OnPostAsync()
        {
            await _appService.CreateAsync(CreateDto);
            return NoContent();
        }
    }
}